package org.apache.struts.pharmacy.pharmacy.action;

import java.util.Date;
import java.util.Map;

import org.apache.struts.pharmacy.pharmacy.model.HL7Message;
import org.apache.struts.pharmacy.pharmacy.model.OrderDrugs;

import com.earogya.communicate.Communicator;
import com.earogya.logic.pharmacy.order.CreateRDEO11Order;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class OrderDrugsAction extends ActionSupport{
	private OrderDrugs orderDrugs;
	private HL7Message message;
	private Date date;

	public HL7Message getMessage() {
		return message;
	}

	public String execute() throws Exception {
		Map<String, Object> session=ActionContext.getContext().getSession();
		CreateRDEO11Order createMessage=new CreateRDEO11Order(orderDrugs);
		String msg=createMessage.createMessage((String)session.get("facility"));
		message=new HL7Message();
		if(!msg.equals(null)){
			Communicator c=new Communicator();
			String reply=c.sendMessage(msg);
			message.setMessage(msg+"-------------"+reply);
		}
		else{
			message.setMessage("empty");
		}
		return SUCCESS;
	}

	public OrderDrugs getOrderDrugs() {
		return orderDrugs;
	}

	public void setOrderDrugs(OrderDrugs orderDrugs) {
		this.orderDrugs = orderDrugs;
	}

	public void validate(){
	}
}
